package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.MemberMapper;
import com.qf.entity.Member;
import com.qf.entity.Pagination;
import com.qf.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberMapper mapper;


    @Override
    public PageInfo<Member> findByPageAndName(Pagination pagination) {
        //设置分页参数
        PageHelper.startPage(pagination.getCurrentPage(),pagination.getPageSize());
        //查询
        List<Member> members = mapper.findByName(pagination.getQueryString());

        //基于查询结果，返回pageInfo
        return new PageInfo<>(members);
    }

    @Override
    public int addMember(Member member) {
        int i = mapper.insert(member);
        return i;
    }

    @Override
    @Transactional
    public int edit(Member member) {
        int edit = mapper.edit(member);
        return edit;
    }

    @Override
    public int delete(Integer id) {
        int delete = mapper.delete(id);
        return delete;
    }

    @Override
    public Member findById(Integer id) {
        Member byId = mapper.findById(id);
       return byId;
    }

    @Override
    public long todayAddMemberCount() {
        return mapper.todayAddMemberCount();
    }

    @Override
    public long weekAddMemberCount() {
        return mapper.weekAddMemberCount();
    }

    @Override
    public long monthAddMemberCount() {
        return mapper.monthAddMemberCount();
    }

    @Override
    public long memberCount() {
        return mapper.memberCount();
    }

    @Override
    public long todayOrderNumber() {
        return mapper.todayOrderNumber();
    }

    @Override
    public long todayVisitsNumber() {
        return mapper.todayVisitsNumber();
    }

    @Override
    public long thisWeekOrderNumber() {
        return mapper.thisWeekOrderNumber();
    }

    @Override
    public long thisWeekVisitsNumber() {
        return mapper.thisWeekVisitsNumber();
    }

    @Override
    public long thisMonthOrderNumber() {
        return mapper.thisMonthOrderNumber();
    }

    @Override
    public long thisMonthVisitsNumber() {
        return mapper.thisMonthVisitsNumber();
    }

    @Override
    public List<Map> findHotSetmeal() {
        return mapper.findHostSetmeal();
    }
}

